#!/usr/bin/env python3
# encoding: utf-8
"""
@author: kevin
@contact: evil365@gmail.com
@project : flask
@file: forms.py
@time: 2020/8/5 11:19
@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
from wtforms import DateTimeField, PasswordField, FieldList, IntegerField, StringField
from wtforms.validators import DataRequired, Regexp, EqualTo, length, Optional, NumberRange


from lin.forms import Form


class ClientSearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdateClientForm(Form):
    userName = StringField(validators=[DataRequired(message='必须传入名称')])
    cardNo = StringField(validators=[DataRequired(message='身份证号不能为空')])
    phone = StringField(validators=[Regexp(r'^[0-1]+[0-9]{7-17}$', message='请输入正确的电话号码'),
                                    Optional()])
    type = StringField(validators=[DataRequired(message='用户类型不能为空')])
    srcId = StringField(validators=[Optional()])
    registTime = DateTimeField(validators=[Optional()])


class BankCardSearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdateBankCardForm(Form):
    userId = StringField(validators=[DataRequired(message='必须传入用户Sn')])
    cardNo = StringField(validators=[DataRequired(message='银行卡号不能为空')])
    status = StringField(validators=[DataRequired(message='请输入正确的电话号码')])
    assetType = StringField(validators=[DataRequired(message='账户类型不能为空')])
    pId = StringField(validators=[Optional()])


class PosionSearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdatePosionForm(Form):
    userId = IntegerField(validators=[DataRequired(message='用户Sn不能为空'),
                                      NumberRange(message='用户Sn必须大于0')])
    productId = IntegerField(validators=[DataRequired(message='产品Sn不能为空'),
                                      NumberRange(message='产品Sn必须大于0')])
    rateSequence = StringField(validators=[DataRequired(message='利率序列不能为空'),
                               Regexp(r'[0-9]+[0-9-%\\]', message='输入正确的序列对')])
    quantity = IntegerField(validators=[DataRequired(message='请输入产品仓位数量'),
                                        Regexp(r'^[0-9]', message='数量只能是数值')])
    parentRateSequence = StringField(validators=[Optional()])
    assetType = StringField(validators=[Optional()])


class RepaySearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdateRepayForm(Form):
    clientPosionSn = IntegerField(validators=[DataRequired(message='用户Sn不能为空'),
                                      NumberRange(message='用户Sn必须大于0')])
    productRepaySn = IntegerField(validators=[DataRequired(message='产品还款计划Sn不能为空'),
                                      NumberRange(message='产品还款计划Sn必须大于0')])
    yieldRate = StringField(validators=[DataRequired(message='利率序列不能为空'),
                               Regexp(r'[0\.]+[0-9]{12}$', message='输入正确的利率')])
    calcCapital = IntegerField(validators=[DataRequired(message='请输入产品计息本金'),
                                        Regexp(r'^[1-9]+[0-9]', message='计息本金只能是数值')])
    capitalBlance = IntegerField(validators=[DataRequired(message='请输入产品还款本金'),
                                        Regexp(r'^[0-9]', message='还款本金只能是数值')])
    yieldBlance = IntegerField(validators=[DataRequired(message='请输入产品还款收益'),
                                        Regexp(r'^[0-9]+[0-9\.]', message='数量只能是数值')])
    status = StringField(validators=[Optional()])
    type = StringField(validators=[Optional()])
